package com.xoms.front.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.xoms.front.controller.res.*;
import com.xoms.front.controller.res.bean.*;
import com.xoms.front.controller.springmvc.req.*;

/**
 * 产品相关接口
 **/
@Controller
@RequestMapping(value = "/product", produces = "application/json")
public class SProductController {
	@Autowired
	com.xoms.front.controller.ProductController productController;

	/**
	 * 获取所有商品分类列表
	 **/
	@RequestMapping("/v1/getAllCategories")
	@ResponseBody
	public ObjectResult<RProCategoryJSONBean> getAllCategories(HttpServletRequest request, HttpServletResponse response) {

		return productController.getAllCategories(request, response);
	}

	/**
	 * 获取商品列表
	 **/
	@RequestMapping("/v1/getAllProducts")
	@ResponseBody
	public ListResult<RAllProductsBean> getAllProducts(@Validated GetAllProductsParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RAllProductsBean> res = new ListResult<RAllProductsBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return productController.getAllProducts(param, request, response);
	}
}
